package com.whl215.kit.adapter.element

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.whl215.kit.adapter.GrapeViewHolder
import com.whl215.kit.adapter.R
import com.whl215.kit.adapter.databinding.GrapeItemElementListStatusBinding

/**
 * author： happiness
 * date： 2021/4/15
 * description：
 */
class ListStatusGrapeElement : GrapeElement() {
    var ableShowListStatus = false


    override fun getViewBinding(parent: ViewGroup): ViewBinding {
        return GrapeItemElementListStatusBinding.inflate(LayoutInflater.from(parent.context),parent,false)
    }

    override fun bindViewHolder(holder: GrapeViewHolder, action: GrapeAction) {
        val viewBinding :GrapeItemElementListStatusBinding = holder.getViewBinding()
        viewBinding.itemElementProgressBar.visibility =
            if (action.code == GrapeAction.LIST_LOADING) View.VISIBLE else View.GONE
        viewBinding.itemElementImgPlaceHolder.visibility =
            if (action.code == GrapeAction.LIST_LOADING) View.GONE else View.VISIBLE
        viewBinding.itemElementTvMessage.text = action.message
        holder
            .setOnClickListener(viewBinding.itemElementTvMessage)
            .setOnClickListener(viewBinding.itemElementImgPlaceHolder)
        if (action.placeHolder != -1)
            viewBinding.itemElementImgPlaceHolder.setImageResource(action.placeHolder)
    }
}